$(function () {

    var data = request("get","system/sys-user/query?username="+sessionStorage.getItem("tongyao-username"),"")
    $("#currentUserId").html(data.data.userNickName+" ("+data.data.sysRole.roleName+")");
    data = request("get","system/sys-menu/queryMenu?roleId="+data.data.sysRole.id,"")

    var menuHtml = ""
    var menuList = data.data
    for(var i = 0;i< menuList.length;i++){

        if(menuList[i].childrenItem.length != 0){

            var childrenItem = menuList[i].childrenItem;
            var childrenItemHtml = ""
            for(var k = 0;k<childrenItem.length;k++){

                if(childrenItem[k].childrenItem.length != 0){

                    var childrenItem3 = childrenItem[k].childrenItem;
                    var childrenItemHtml3 = ""
                    for(var j = 0;j < childrenItem3.length;j++){

                        childrenItemHtml3 = childrenItemHtml3 +
                        "        <li>" +
                        "            <a class='J_menuItem' href='"+childrenItem3[j].menuPath+"' data-index='9'><i class='"+childrenItem3[j].menuIcon+"'></i>"+childrenItem3[j].menuName+"</a>" +
                        "        </li>";
                    }
                    childrenItemHtml = childrenItemHtml +
                        "<li>" +
                        "    <a href='#'>" +
                        "        <i class='"+childrenItem[k].menuIcon+"'></i>" +
                        "        <span class='nav-label'>"+childrenItem[k].menuName+"</span>" +
                        "        <span class='fa arrow'></span>" +
                        "    </a>" +
                        "    <ul class='nav nav-third-level collapse' aria-expanded='false' style='height: 0px;'>" +
                                childrenItemHtml3+
                        "    </ul>";
                        "</li>";
                }else{
                    childrenItemHtml = childrenItemHtml +
                        "        <li>" +
                        "            <a class='J_menuItem' href='"+childrenItem[k].menuPath+"' data-index='9'>"+childrenItem[k].menuName+"</a>" +
                        "        </li>";
                }
            }


            menuHtml = menuHtml +
                "<li>" +
                "    <a href='#'>" +
                "        <i class='"+menuList[i].menuIcon+"'></i>" +
                "        <span class='nav-label'>"+menuList[i].menuName+"</span>" +
                "        <span class='fa arrow'></span>" +
                "    </a>" +
                "    <ul class='nav nav-second-level collapse' aria-expanded='false' style='height: 0px;'>" +
                        childrenItemHtml+
                "    </ul>";
                "</li>";
        }else{
            menuHtml = menuHtml +
                "<li>" +
                "    <a class='J_menuItem' href='"+menuList[i].menuPath+"' data-index='86'>" +
                "        <i class='fa fa-magic'></i>" +
                "        <span class='nav-label'>"+menuList[i].menuName+"</span>" +
                "    </a>" +
                "</li>";
        }

    }
    $("#side-menu").html(menuHtml);
    $("[name=exit]").click(function () {
        data = request("get","logout","")
        sessionStorag.removeAll();
        window.location.href = "login.html"
    })
})

